package com.witframework.dynoengine;

import java.sql.Types;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Component;
import org.springframework.web.util.WebUtils;

import com.witframework.core.persistence.JdbcTools;
import com.witframework.dynoengine.model.WitMetaColumn;
import com.witframework.web.mvc.WebContext;

@Component
public class StoreServlet {
	public String executor(WebContext webContext){
		String tableId=(String)webContext.getParamOrAttr("dynoTableId");
		String tableName=MetaFactory.getInstance().getMetaTableById(tableId).getTableName();
		Map<String, String> data = WebUtils.getParametersStartingWith(webContext.getHttpRequest(),"");
		JdbcTools.insert(tableName, convert(tableId,data));
		return null;
	}
	private Map<String,Object> convert(String tableId,Map<String,String> data){
		Map<String,Object> dataMap=new HashMap();
		List mfList=MetaFactory.getInstance().getMetaFileds(tableId);
		Iterator keyItor=data.keySet().iterator();
		while(keyItor.hasNext()){
			String fieldName=(String)keyItor.next();
			WitMetaColumn mf=MetaFactory.getInstance().getMetaFiled(tableId, fieldName);
			if(mf!=null){
				int columnType=mf.getColumnType();
				String value=(String)data.get(fieldName);
				
			}
		}
		return dataMap;
	}
}
